Appium提示Failed to start an Appium session

问题

Python + Appium执行脚本提示:

1
error: Failed to start an Appium session, err was: Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c ""E:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe" -s eaf4e6a6 shell "ps 'uiautomator'""

原因分析

测试机的系统为Android 7,不支持ps ‘uiautomator’这种命令格式

解决方案

修改 ..\appium\node_modules\appium-adb\lib\adb.js文件,line:1035

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
this.shell("ps '" + name + "'", function (err, stdout) {
if (err) return cb(err);
替换成
this.shell_grep("ps", name, function (err, stdout) {
if (err) {
logger.debug("No matching processes found");
return cb(null, []);
}
并增加上面用到的shell_grep函数:
ADB.prototype.shell_grep = function (cmd, grep, cb) {
if (cmd.indexOf('"') === -1) {
cmd = '"' + cmd + '"';
}
var execCmd = 'shell ' + cmd + '| grep ' + grep;
this.exec(execCmd, cb);
};

欢迎打赏!